<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ page import="org.tools.wstt.reference.ApplicationComponent"%>
<c:set var="title" scope="request">Simulate HTTP Responses</c:set>

<jsp:include page="/WEB-INF/jsp/inc/head.jsp" />

		<h2>Response Configuration</h2>

		<c:if test="${!empty param.load_resp_id}">
			<c:set var="loadedHeaders"><c:out value="${applicationScope['responsesMap'][param.load_resp_id].headers}" /></c:set>
			<c:set var="loadedContent"><c:out value="${applicationScope['responsesMap'][param.load_resp_id].content}" /></c:set>
		</c:if>
		<h3>Create a response</h3>
		<form method="POST" action="<c:out value="${servicesPath}" /><%=ApplicationComponent.URI_RESP_MANAGE %>">
			<p>
				<input type="hidden" name="action" value="create" />
				<input type="hidden" name="resp_id" value="<c:out value="${param.load_resp_id}" />" />
				<label for="httpHeaders">HTTP Headers : </label><textarea rows="5" cols="70" id="httpHeaders" type="text" name="httpHeaders"><c:out value="${loadedHeaders}" escapeXml="false" /></textarea><br />
				<label for="httpContent">HTTP Content : </label><textarea rows="10" cols="70" id="httpContent" type="text" name="httpContent"><c:out value="${loadedContent}" escapeXml="false" /></textarea><br />
				<input type="submit" value="Save Response" />
			</p>
		</form>

		<h3>Responses availables</h3>
		<p><em>Responses are not persisted but kept in memory. So, when this server restarts or the application is redeployed, the list of available responses will be empty.</em></p>
		<table>
			<tbody>
				<tr>
					<th>Response ID</th>
					<th>Headers</th>
					<th>Content</th>
					<th>Actions</th>
				</tr>
				<c:forEach var="entry" items="${applicationScope['responsesMap']}">
					<tr>
						<td><a href="<%=request.getContextPath() %><%=ApplicationComponent.URI_RESP_MANAGE %>?resp_id=<c:out value="${entry.value.id}" />#rawcontent" title="use this response"><c:out value="${entry.value.id}" /></a></td>
						<td><c:out value="${entry.value.headers}" /></td>
						<td><c:out value="${entry.value.content}" /></td>
						<td>
							<form action="<c:out value="${servicesPath}" /><%=ApplicationComponent.URI_RESP_MANAGE %>" method="POST">
								<input type="hidden" name="resp_id" value="<c:out value="${entry.value.id}" />" />
								<input type="submit" name="action" value="Edit" />
								<input type="submit" name="action" value="Delete" />
							</form> 
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
		
		<c:if test="${!empty requestScope['contentRequested']}">
			<h2>Raw Content of Response "<c:out value="${param.resp_id}" />"</h2>
			<p><em>To view HTTP Headers in the response, you may use "Developer Tools" in Google Chrome or the "Firebug" extension in Firefox.</em></p>
			<div id="rawcontent" style="border: 1px solid #bbb;margin-top:20px;padding:10px;">
				<c:out value="${requestScope['contentRequested']}" escapeXml="false" />
			</div>
		</c:if>
		
<jsp:include page="/WEB-INF/jsp/inc/foot.jsp" />